package com.zhengjiang.log4j2.demo.controller;

import com.zhengjiang.log4j2.demo.exception.ServiceException;
import com.zhengjiang.log4j2.demo.model.BaseResult;
import com.zhengjiang.log4j2.demo.model.enums.ResponseCodeEnum;
import com.zhengjiang.log4j2.demo.model.params.QueryUserParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @ClassName DemoController
 * @Description
 * @Author zhengjiang(99514925 @ qq.com)
 * @Date 2020-06-24 15:45
 * @Version V1.0
 **/
@Slf4j
@RestController
public class DemoController {

    @GetMapping("/hello")
    public String hello(String name){
        log.debug("hello {}",name);
        return String.format("hello %s !",name);
    }

    @PostMapping("/queryUser")
    public BaseResult<String> queryUser(@Valid @RequestBody QueryUserParam param){
        try {
            if (1==1){
                throw new ServiceException(ResponseCodeEnum.SYSTEM_ERROR.getCode(),ResponseCodeEnum.SYSTEM_ERROR.getMsg());
            }
        }catch (RuntimeException e){
            log.error(e.getMessage());
        }

        return BaseResult.success("测试");
    }

}
